package atguigu.demo3

import scala.collection.mutable.ArrayBuffer

/**
  * Created by lzd on 2018/10/29.
  * 数组操作
  */
object demo3_1 {
  def main(args: Array[String]): Unit = {
    /**定长数组*/
    val array = new Array[Int](3)
    val s = Array(1,2,3)
    println(array.toBuffer)
    s(0)=11
    println(s.toBuffer)


    val b = ArrayBuffer[Int]()
    val bb = new ArrayBuffer[Int]

    b += 1
    b += (1, 2, 3, 5)
    println(b)
    b ++= Array(8, 13, 21)
    println(b)
    bb++=b
    println(bb)

    //删除后5个
    b.trimEnd(5)
    println(b)

    //在第三个插入6,66,666
    b.insert(2,6,66,666)
    println(b)

    //移除第三个位置
    b.remove(2)
    println(b)
    //删除第三个位置的，3个元素
    b.remove(2,3)
    println(b)

    //变长数组转定长数组
    val imb = b.toArray

    val forarr = Array(11,21,3,4,55,6,7,8)
    //下标访问
    for(i <- 0 until forarr.length){
      println(forarr(i))
    }

    //产生一个范围(range)
    println(0 until forarr.length)

    //产生一个范围(range),以2隔开
    println(0 until (forarr.length,2))

    // Range倒转
    println((0 until forarr.length).reverse)

    //forarr 索引
    for(a <- forarr.indices){
      print(a+"\t")
    }
  }
}
